<template>
  <!-- 对话框 -->
  <div>
    <el-dialog :title="dialogTitle" :visible="dialogVisible" width="35%" :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">

            <el-form-item prop="name" label="name">
              <el-input v-model="form.name" size="mini" placeholder="请输入" />
            </el-form-item>

            <el-form-item prop="type" label="type">
              <el-input v-model="form.type" size="mini" placeholder="请输入" />
            </el-form-item>

            <el-form-item prop="orderIndex" label="排序">
              <el-input v-model="form.orderIndex" size="mini" placeholder="请输入排序" />
            </el-form-item>

            <div>
              <input type="file" @change="uploadFile" />
            </div>

            <!-- <img v-if="form.id" style="margin-top: 5px;" :src= "imgBaseUrl + form.id" width="30px"/> -->


        <el-form-item>
          <el-row type="flex" justify="end" style="margin-top: 10px;">
            <el-button size="mini" @click="handleClose">取 消</el-button>
            <el-button size="mini" type="primary" @click="btnOK">确 定</el-button>
          </el-row>
        </el-form-item>
      </el-form>

    </el-dialog>

  </div>

</template>

<script>
import baseData from '@/baseData'
export default {
  name: 'TypeAdd',
  props: {
    dialogVisible: {
      default: false,
      type: Boolean
    },
    dialogTitle:'',
    form:{},
    options:[],
    data:null,
  },
  data() {
    return {
      imgBaseUrl:baseData.basePathUser+'/tbFile/fileById?id=',
      rules:[],
      file:null
    }
  },
  watch: {
    
  },
  mounted() {

  },

  methods: {
    // 取消
    handleClose() {
      this.$emit('update:dialogVisible', false)
    },

    // 确定
    async btnOK() {
        const formData = new FormData()
        formData.append('file', this.file)
        formData.append('name', this.form.name)
        formData.append('type', this.form.type)
        formData.append('orderIndex', this.form.orderIndex)
        // 处理响应
        this.data.fn.submit(formData)

    },
   
    Close() {
      this.showVisible = false
      this.handleClose()
    },
    uploadFile(event) {
      const file = event.target.files[0];
      this.file=file
    },

  }
}
</script>

<style lang="scss" scoped></style>
